#include<stdio.h>
#define MAXSIZE 100
int Comb(int n, int m);
int main()
{
    freopen("in.txt","r",stdin);
    int n,m;
    printf("请输入n和m\n");
    scanf("%d %d",&m,&n);
    //printf("栈顶指针    [top][1]    [top][2]    [top][3]\n");
    printf("C(%d,%d)=%d\n",n,m,Comb(n,m));
} 
int Comb(int n,int m)
{
    int s1,s2;
    int Stack[MAXSIZE][3], top = 0;
    if(n < m || n <= 0 || m <= 0)
    {
        printf("输入错误");
        return 0;
    }
    Stack[top][0] = 0;
    Stack[top][1] = n;
    Stack[top][2] = m;
    top++;
    do
    {
        //printf("top=%d:%8d,%8d,%8d\n",top,Stack[top-1][0],Stack[top-1][1],Stack[top-1][2]);
        if(Stack[top-1][0] == 0)
        {
            Stack[top][0] = 0;
            Stack[top][1] = Stack[top-1][1] - 1;
            Stack[top][2] = Stack[top-1][2];
            if(Stack[top][2] == 0 || Stack[top][1] == Stack[top][2])
            {
                Stack[top][0] = 1;
            }
            top++;
        }
        if(top >= 2 && Stack[top-1][0] > 0 && Stack[top-2][0] == 0)
        {
            Stack[top][0] = 0;
            Stack[top][1] = Stack[top-2][1] - 1;
            Stack[top][2] = Stack[top-2][2] - 1;
            if(Stack[top][2] == 0)
            {
                Stack[top][0] = 1;
            }
            top++;
        }
        if(top >= 2 && Stack[top-1][0] > 0 && Stack[top-2][0] > 0)
        {
            s1 = Stack[top-1][0];
            s2 = Stack[top-2][0];
            top = top - 2;
            Stack[top-1][0] = s1 + s2;
        }

    } while (top > 1);
    return Stack[top-1][0];
}
